/*
 * global.cpp
 *
 *  Created on: 2019年2月16日
 *      Author: bx-fantx
 */



#include "BxGlobal.h"
#include "../utils/utils.h"
#include "../fpgaControl/onbonsource.h"

using namespace std;

Global* Global::_p_global = NULL;

class Global *g_Global = NULL;
class onbonsource* g_OnbonSource = NULL;
class fpga_manage* g_FpgaManage = NULL;
class message_deal* g_MessageDeal = NULL;
Oint32  g_AppExit=0;
Ouint32 OVP_CONTROL_FPGA1 = 0x0B4E; // A10 0x0B4D;  A16 0B4E; A6 0x0B4C;
Ouint8 OVP_CONTROL_OUT_EACH_CARD_NET_NUM = 16;
Ouint8 OVP_CONTROL_OUT_NUM = 1;

//about flash addr
Ouint32 FLASH_SEC_SIZE =  4096; //用于扇区的读写
Ouint32 PARAM1_SEC = 1728;//441//442//(127)  //参数区1
Ouint32 PARAM1_SEC_ADDR = (PARAM1_SEC*FLASH_SEC_SIZE);

Ouint32 RAM1_SEC = 1735;        //LCD para
Ouint32 RAM1_ADD =  (RAM1_SEC*FLASH_SEC_SIZE);

Ouint32 TIME_FLAG = 1775;    //工程运行标志区
Ouint32 TIME_FLAG_ADD = (TIME_FLAG*FLASH_SEC_SIZE) ;

Ouint32 ONOFF_SEC = 1741;//893//396     //定时开关参数区
Ouint32 ONOFF_ADD = (ONOFF_SEC*FLASH_SEC_SIZE);
Ouint32 BRIGHT_SEC = 1742;//894//397     //调亮参数区
Ouint32 BRIGHT_ADD = (BRIGHT_SEC*FLASH_SEC_SIZE);

Ouint32 RAM_PARA_START_SEC = 1735;//886//384			//!<RAM参数
Ouint32 RAM_PARA_END_SEC = 1735;//886//384			//!<RAM参数

Ouint32 PC_NET_PARA_SEC = 1776;//922//(482) //PC备用扇区 用于PC记录网口参数

Ouint32 RAM_PARA_BASE_ADD = (Ouint32)(RAM_PARA_START_SEC*FLASH_SEC_SIZE);//!<MCU 中 RAM 参数的保存位置。

Ouint32 PC_NET_PARA_ADDR = (PC_NET_PARA_SEC*FLASH_SEC_SIZE);

//c331 fpga flash
Ouint32 C331_FLASH_SEC_MAX = 8192;//2048,//8M
Ouint32 C331_FLASH_MAX_ADDR = (FLASH_SEC_SIZE*C331_FLASH_SEC_MAX);

//FPGA1 FLASH 8M
Ouint32 FPGA_FLASH_VBYONE1_SEC_MAX = 2048;//8M
Ouint32 FPGA_FLASH_VBYONE1_MAX_ADDR = (FLASH_SEC_SIZE*FPGA_FLASH_VBYONE1_SEC_MAX);

//FPGA2 FLASH
Ouint32 FPGA_FLASH_VBYONE2_SEC_MAX =	2048;
Ouint32 FPGA_FLASH_VBYONE2_MAX_ADDR = (FPGA_FLASH_VBYONE2_SEC_MAX*FLASH_SEC_SIZE);

Ouint32 SOURCE_CHIP_SEC_MAX = 16;
Ouint32 SOURCE_CHIP_FLASH_MAX_ADDR = (SOURCE_CHIP_SEC_MAX*FLASH_SEC_SIZE);


Global::Global() {
//	for(vector<string>::const_iterator it=GlobalDefine::CONFIG_NAME_LIST.begin(); it!=GlobalDefine::CONFIG_NAME_LIST.end();++it){
//		cout << *it << endl;
//	}
}

Global::~Global() {
	if (Global::_p_global){
		_p_global = NULL;
	}
}

Global* Global::pInstance()
{
	if (Global::_p_global == NULL){
		_p_global = new Global();
	}
	return _p_global;
}



/*!
 * 全局变量初始化
 * @param :
 * @return :
 * @note :
 */
void Global::init_global_variable()
{
	//! 获取临时配置
    g_controller_name = "OVP-A16";
	//! 初始化备份配置全局变量
    OVP_CONTROL_OUT_NUM = 1;
    if (g_controller_name == "OVP-A16")
    {
        OVP_CONTROL_FPGA1 = 0x0B4E;// A10 0x0B4D;  A16 0B4E; A6 0x0B4C;
        OVP_CONTROL_OUT_EACH_CARD_NET_NUM = 16;

        FLASH_SEC_SIZE =  4096; //用于扇区的读写
        PARAM1_SEC = 1728;//441//442//(127)  //参数区1
        PARAM1_SEC_ADDR = (PARAM1_SEC*FLASH_SEC_SIZE);

        RAM1_SEC = 1735;        //LCD para
        RAM1_ADD =  (RAM1_SEC*FLASH_SEC_SIZE);

        TIME_FLAG = 1775;    //工程运行标志区
        TIME_FLAG_ADD = (TIME_FLAG*FLASH_SEC_SIZE) ;

        ONOFF_SEC = 1741;//893//396     //定时开关参数区
        ONOFF_ADD = (ONOFF_SEC*FLASH_SEC_SIZE);
        BRIGHT_SEC = 1742;//894//397     //调亮参数区
        BRIGHT_ADD = (BRIGHT_SEC*FLASH_SEC_SIZE);

        RAM_PARA_START_SEC = 1735;//886//384			//!<RAM参数
        RAM_PARA_END_SEC = 1735;//886//384			//!<RAM参数

        PC_NET_PARA_SEC = 1776;//922//(482) //PC备用扇区 用于PC记录网口参数
    }else
    {
        if (g_controller_name == "OVP-A6")
        {
            OVP_CONTROL_FPGA1 = 0x0B4C;
            OVP_CONTROL_OUT_EACH_CARD_NET_NUM = 6;
        }else if (g_controller_name == "OVP-A10")
        {
            OVP_CONTROL_FPGA1 = 0x0B4D;
            OVP_CONTROL_OUT_EACH_CARD_NET_NUM = 10;
        }
        
        
        FLASH_SEC_SIZE =  4096; //用于扇区的读写
        PARAM1_SEC = 769;//441//442//(127)  //参数区1
        PARAM1_SEC_ADDR = (PARAM1_SEC*FLASH_SEC_SIZE);

        RAM1_SEC = 776;        //LCD para
        RAM1_ADD =  (RAM1_SEC*FLASH_SEC_SIZE);

        TIME_FLAG = 816;    //工程运行标志区
        TIME_FLAG_ADD = (TIME_FLAG*FLASH_SEC_SIZE) ;

        ONOFF_SEC = 782;//893//396     //定时开关参数区
        ONOFF_ADD = (ONOFF_SEC*FLASH_SEC_SIZE);
        BRIGHT_SEC = 783;//894//397     //调亮参数区
        BRIGHT_ADD = (BRIGHT_SEC*FLASH_SEC_SIZE);

        RAM_PARA_START_SEC = 776;//886//384			//!<RAM参数
        RAM_PARA_END_SEC = 776;//886//384			//!<RAM参数

        PC_NET_PARA_SEC = 817;//922//(482) //PC备用扇区 用于PC记录网口参数
    }  

    RAM_PARA_BASE_ADD = (Ouint32)(RAM_PARA_START_SEC*FLASH_SEC_SIZE);//!<MCU 中 RAM 参数的保存位置。

    PC_NET_PARA_ADDR = (PC_NET_PARA_SEC*FLASH_SEC_SIZE);

//c331 fpga flash
    C331_FLASH_SEC_MAX = 8192;//2048,//8M
    C331_FLASH_MAX_ADDR = (FLASH_SEC_SIZE*C331_FLASH_SEC_MAX);

//FPGA1 FLASH 8M
    FPGA_FLASH_VBYONE1_SEC_MAX = 2048;//8M
    FPGA_FLASH_VBYONE1_MAX_ADDR = (FLASH_SEC_SIZE*FPGA_FLASH_VBYONE1_SEC_MAX);

//FPGA2 FLASH
    FPGA_FLASH_VBYONE2_SEC_MAX =	2048;
    FPGA_FLASH_VBYONE2_MAX_ADDR = (FPGA_FLASH_VBYONE2_SEC_MAX*FLASH_SEC_SIZE);

    SOURCE_CHIP_SEC_MAX = 16;
    SOURCE_CHIP_FLASH_MAX_ADDR = (SOURCE_CHIP_SEC_MAX*FLASH_SEC_SIZE);

}
